﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class FA_GhiTangGiamTaiSan
    {
        private double mDaKhauHao = 0.0;
        private string mDienGiai = "";
        private string mDuLieu = "";
        private int mDuyet = 0;
        private string mKhoa = "";
        private string mKhoaDonVi = "";
        private string mKhoaLyDo = "";
        private string mKhoaTaiSanCoDinh = "";
        private int mLoai = 0;
        private string mLoaiTien = "";
        private string mNgayChungTu = "";
        private double mNguyenGia = 0.0;
        private double mNguyenGiaNT = 0.0;
        private int mSend = 0;
        private string mSoChungTu = "";
        private int mSoThangKhauHao = 0;
        private double mTongThue = 0.0;
        private double mTongThueNT = 0.0;
        private double mTongTien = 0.0;
        private double mTongTienNT = 0.0;
        private double mTriGiaConLai = 0.0;
        private double mTriGiaKhauHao = 0.0;
        private double mTyGia = 0.0;

        public void ClearTemp(string strKhoa)
        {
            string commandText = "DELETE FROM FA_ChungTuTangGiamTaiSanChiTietTmp WHERE KhoaChungTu = '" + strKhoa.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool Delete(string strKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_sp_ChungTuTangGiamTaiSanDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[1].Value, 0, false))
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDetails(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "SELECT CT.Khoa, CT.KhoaTaiKhoanNo, TKN.SoTaiKhoan as TaiKhoanNo, CT.KhoaTaiKhoanCo, TKC.SoTaiKhoan as TaiKhoanCo,  CT.KhoaDoiTuong, DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong, CT.KhoaTaiKhoanThue, TKT.SoTaiKhoan as TaiKhoanThue,  CT.KhoaBoPhan, BP.Ten" + modGeneral.H_LANGUAGE + " as BoPhan, CT.KhoaSanPham, SP.Ten" + modGeneral.H_LANGUAGE + " as SanPham,  CT.KhoaHopDong, HD.SoHopDong as HopDong, CT.KhoaDoiTuongThue, CT.TenDoiTuongThue, CT.MaSoThue, CT.DiaChiThue, CT.KhoaLoaiThue,  LHD.Ma as LoaiHoaDon, CT.TyLeThue, CT.SoHoaDon, dbo.Char2Date(CT.NgayHoaDon) as NgayHoaDon, CT.Soseri, CT.TienThueNT, CT.TienThue,  CT.SoTienNT, CT.SoTien, CT.DienGiai  FROM FA_ChungTuTangGiamTaiSanChiTiet CT  LEFT JOIN DM_TaiKhoan TKN ON CT.KhoaTaiKhoanNo = TKN.Khoa  LEFT JOIN DM_TaiKhoan TKC ON CT.KhoaTaiKhoanCo = TKC.Khoa  LEFT JOIN DM_TaiKhoan TKT ON CT.KhoaTaiKhoanThue = TKT.Khoa  LEFT JOIN DM_DoiTuong DT ON CT.KhoaDoiTuong = DT.Khoa  LEFT JOIN DM_DonViBoPhan BP ON CT.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP ON CT.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD ON CT.KhoaHopDong = HD.Khoa  LEFT JOIN DM_LoaiHoaDon LHD ON CT.KhoaLoaiThue = LHD.Khoa  WHERE CT.KhoaChungTu = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetList(string strConditions = "")
        {
            string commandText = "SELECT T.Khoa, T.SoChungTu, dbo.Char2Date(T.NgayChungTu) As Ngay, TS.Ma As MaTaiSan, TS.TenViet As TenTaiSan,  T.NguyenGiaNT, T.NguyenGia, T.DienGiai  FROM FA_ChungTuTangGiamTaiSan T Left join FA_TaiSanCoDinh TS ON T.KhoaTaiSanCoDinh = TS.Khoa ";
            if (strConditions.Trim() != "")
            {
                commandText = commandText + " WHERE 1 = 1 AND " + strConditions;
            }
            commandText = commandText + " ORDER BY T.NgayChungTu, T.SoChungTu ";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public bool Load(string pKhoa, int pLoai)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM FA_ChungTuTangGiamTaiSan WHERE Khoa = '" + pKhoa + "' and Loai = " + Conversions.ToString(pLoai);
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiSanCoDinh = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGiaNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetDecimal));
                    this.mDaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetDecimal));
                    this.mTriGiaConLai = Conversions.ToDouble(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoThangKhauHao = Conversions.ToInteger(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetInt32));
                    this.mTriGiaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetInt32));
                    this.mTongTienNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongTien = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mLoai = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaLyDo = Conversions.ToString(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetString));
                    dataReader.Close();
                    return true;
                }
                dataReader.Close();
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool LoadByTaiSan(string pKhoaTaiSan, int pLoai)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM FA_ChungTuTangGiamTaiSan WHERE KhoaTaiSanCoDinh = '" + pKhoaTaiSan + "' and Loai = " + Conversions.ToString(pLoai);
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiSanCoDinh = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGiaNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetDecimal));
                    this.mDaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetDecimal));
                    this.mTriGiaConLai = Conversions.ToDouble(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoThangKhauHao = Conversions.ToInteger(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetInt32));
                    this.mTriGiaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetInt32));
                    this.mTongTienNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongTien = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mLoai = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaLyDo = Conversions.ToString(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetString));
                    dataReader.Close();
                    return true;
                }
                dataReader.Close();
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x19];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaTaiSanCoDinh", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiSanCoDinh);
                commandParameters[2] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[3] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[4] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[5] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[6] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[7] = DBHelper.createParameter("@NguyenGiaNT", DbType.Date, ParameterDirection.Input, this.mNguyenGiaNT);
                commandParameters[8] = DBHelper.createParameter("@NguyenGia", DbType.Date, ParameterDirection.Input, this.mNguyenGia);
                commandParameters[9] = DBHelper.createParameter("@DaKhauHao", DbType.Date, ParameterDirection.Input, this.mDaKhauHao);
                commandParameters[10] = DBHelper.createParameter("@TriGiaConLai", DbType.Date, ParameterDirection.Input, this.mTriGiaConLai);
                commandParameters[11] = DBHelper.createParameter("@SoThangKhauHao", DbType.Double, ParameterDirection.Input, this.mSoThangKhauHao);
                commandParameters[12] = DBHelper.createParameter("@TriGiaKhauHao", DbType.Date, ParameterDirection.Input, this.mTriGiaKhauHao);
                commandParameters[13] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[14] = DBHelper.createParameter("@Send", DbType.Double, ParameterDirection.Input, this.mSend);
                commandParameters[15] = DBHelper.createParameter("@TongTienNT", DbType.Date, ParameterDirection.Input, this.mTongTienNT);
                commandParameters[0x10] = DBHelper.createParameter("@TongTien", DbType.Date, ParameterDirection.Input, this.mTongTien);
                commandParameters[0x11] = DBHelper.createParameter("@TongThueNT", DbType.Date, ParameterDirection.Input, this.mTongThueNT);
                commandParameters[0x12] = DBHelper.createParameter("@TongThue", DbType.Date, ParameterDirection.Input, this.mTongThue);
                commandParameters[0x13] = DBHelper.createParameter("@Loai", DbType.Double, ParameterDirection.Input, this.mLoai);
                commandParameters[20] = DBHelper.createParameter("@KhoaLyDo", DbType.Int64, ParameterDirection.Input, this.mKhoaLyDo);
                commandParameters[0x15] = DBHelper.createParameter("@DuLieu", DbType.Int64, ParameterDirection.Input, this.mDuLieu);
                commandParameters[0x16] = DBHelper.createParameter("@Duyet", DbType.Double, ParameterDirection.Input, this.mDuyet);
                commandParameters[0x17] = DBHelper.createParameter("@pAmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[0x18] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_sp_ChungTuTangGiamTaiSan", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x18].Value, 0, false))
                {
                    return true;
                }
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x17].Value, 0, false))
                {
                    LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện v\x00ec \x00e2m quỹ", ""));
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public double DaKhauHao
        {
            get
            {
                return this.mDaKhauHao;
            }
            set
            {
                this.mDaKhauHao = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DuLieu
        {
            get
            {
                return this.mDuLieu;
            }
            set
            {
                this.mDuLieu = value;
            }
        }

        public int Duyet
        {
            get
            {
                return this.mDuyet;
            }
            set
            {
                this.mDuyet = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public object KhoaLyDo
        {
            get
            {
                return this.mKhoaLyDo;
            }
            set
            {
                this.mKhoaLyDo = Conversions.ToString(value);
            }
        }

        public string KhoaTaiSanCoDinh
        {
            get
            {
                return this.mKhoaTaiSanCoDinh;
            }
            set
            {
                this.mKhoaTaiSanCoDinh = value;
            }
        }

        public int Loai
        {
            get
            {
                return this.mLoai;
            }
            set
            {
                this.mLoai = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public double NguyenGia
        {
            get
            {
                return this.mNguyenGia;
            }
            set
            {
                this.mNguyenGia = value;
            }
        }

        public double NguyenGiaNT
        {
            get
            {
                return this.mNguyenGiaNT;
            }
            set
            {
                this.mNguyenGiaNT = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public int SoThangKhauHao
        {
            get
            {
                return this.mSoThangKhauHao;
            }
            set
            {
                this.mSoThangKhauHao = value;
            }
        }

        public double TongThue
        {
            get
            {
                return this.mTongThue;
            }
            set
            {
                this.mTongThue = value;
            }
        }

        public double TongThueNT
        {
            get
            {
                return this.mTongThueNT;
            }
            set
            {
                this.mTongThueNT = value;
            }
        }

        public double TongTien
        {
            get
            {
                return this.mTongTien;
            }
            set
            {
                this.mTongTien = value;
            }
        }

        public double TongTienNT
        {
            get
            {
                return this.mTongTienNT;
            }
            set
            {
                this.mTongTienNT = value;
            }
        }

        public double TriGiaConLai
        {
            get
            {
                return this.mTriGiaConLai;
            }
            set
            {
                this.mTriGiaConLai = value;
            }
        }

        public double TriGiaKhauHao
        {
            get
            {
                return this.mTriGiaKhauHao;
            }
            set
            {
                this.mTriGiaKhauHao = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

